package com.btf.push;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser;

import android.util.Log;

public class BlackRosterPacketProvider implements IQProvider {

	@Override
	public IQ parseIQ(XmlPullParser parser) throws Exception {
		// TODO Auto-generated method stub
		return parseRoster(parser);
	}
	
	private static BlackRosterPacket parseRoster(XmlPullParser parser) throws Exception {
     
        BlackRosterPacket gpsPacket = new BlackRosterPacket();
        boolean done = false;
        BlackRosterPacket.Item item = null;
        Log.i("VV", "dfdfg parseRoster");
        while (!done) {
        	Log.i("VV", "BlackRosterPacket parseRoster");
            int eventType = parser.next();
            Log.i("VV", eventType+" 88888");
            if (eventType == XmlPullParser.START_TAG) {
            	Log.i("VV", parser.getName());
                if (parser.getName().equals("item")) {
                    String jid = parser.getAttributeValue("", "jid");
                    String action = parser.getAttributeValue("", "action");
                    item = new BlackRosterPacket.Item(jid, null, action);
                    String note = parser.getAttributeValue("", "note");
                    String role = parser.getAttributeValue("", "role");
                    String bday = parser.getAttributeValue("", "bday");
                    String nickname = parser.getAttributeValue("", "nickname");
                    String photo = parser.getAttributeValue("", "photo");
                    item.setNote(note);
                    item.setRole(role);
                    item.setBday(bday);
                    item.setNickname(nickname);
                    item.setPhoto(photo);
                }
                
            }
            else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("item")) {
                	gpsPacket.addRosterItem(item);
                }
                if (parser.getName().equals("blackList")) {
                    done = true;
                }
            }
        }
        return gpsPacket;
    }


}
